package org.hishenframework.tool;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class EntityUtils {
	/**
	 * 下划线转大写
	 * @param text
	 * @return
	 */
	public static String underlinToUpperCase(String text) {
		Pattern pattern = Pattern.compile("(_[a-z])");
		Matcher matcher = pattern.matcher(text);
		while (matcher.find()) {
			text = text.replace(matcher.group(1), matcher.group(1).substring(1).toUpperCase());
		}
		return text.substring(0, 1).toLowerCase() + text.substring(1);
	}

	/**
	 * 大写转下划线
	 * @param text
	 * @return
	 */
	public static String upperCaseToUnderline(String text) {
		Pattern pattern = Pattern.compile("([A-Z])");
		Matcher matcher = pattern.matcher(text);
		while (matcher.find()) {
			text = text.replace(matcher.group(1), "_" + matcher.group(1).toLowerCase());
		}
		if(text.substring(0, 1).equals("_")) {
			text = text.substring(1);
		}
		return text;
	}

	/**
	 * 首字母转小写
	 * @param text
	 * @return
	 */
	public static String firstLetterLowercase(String text) {
		return text.substring(0, 1).toLowerCase() + text.substring(1);
	}
}
